#ifndef TCPSOCKET_H
#define TCPSOCKET_H

#include <sstream>
#include <string>
#include "socket_include.h"
#include "Socket.h"
#include "SSLInitializer.h"


class TCPSocket : public Socket {
public:
	class Reader
	{
	public:
		Reader(Socket * s) : s(s){}
		int read(char * str, int size) {
			return ::recv( s->GetSocket(), str, size, 0 );
		};
		const Reader& operator=(const Reader& rhs) {
		s = rhs.s;
    };
	private:
		Socket * s;
	};
	class Writer
	{
	public:
		Writer(Socket * s) : s(s){};
		int write(const char * str, int size){
			return ::send( s->GetSocket(), str, size, 0 );
		};
		const Writer& operator=(const Writer& rhs) {
			s = rhs.s;
		};
	private:
		Socket * s;
	};
	TCPSocket(ISocketHandler & h);
	~TCPSocket();
	bool Open(std::string & serverName, int port);
	bool Open(const char * serverName, int port);
	void initIOStream();

private:
	static	SSLInitializer m_ssl_init;
	SSL_CTX *m_ssl_ctx; ///< ssl context
	SSL *m_ssl; ///< ssl 'socket'
	BIO *m_sbio; ///< ssl bio
	std::string m_password; ///< ssl password
	Reader r;
	Writer w;

};


#endif //TCPSOCKET_H
